//package com.example.a2209_mianshi.auth
//
//import android.app.Activity
//import android.content.BroadcastReceiver
//import android.content.Context
//import android.content.Intent
//import android.content.IntentFilter
//import android.net.Uri
//import com.example.a2209_mianshi.appContext
//import com.example.a2209_mianshi.flow_eventbus.utils.ToastUtils
//
//
///**
// *
// * 赛科龙授权登录帮助类
// */
class CycloneAuthHelper {
//
//    companion object {
//        private var instance: CycloneAuthHelper? = null
//        fun getInstance(): CycloneAuthHelper {
//            return instance ?: synchronized(this) {
//                instance ?: CycloneAuthHelper().also { instance = it }
//            }
//        }
//
//        val AUTH_URL: String
//            get() = if (BuildConfig.FLAVOR_version.contains("product")) {
//                "cyclone://com.jczy.cyclone/auth?type=7&user_package_name=${appContext.applicationInfo.packageName}"
//            } else {
//                "cyclone://com.jczy.cyclone.dev/auth?type=7&user_package_name=${appContext.applicationInfo.packageName}"
//            }
//
//        //授权Action
//        const val ACTION_AUTH = "com.jczy.cyclone.AUTHORIZATION"
//
//        const val AUTH_OK = 0
//        const val AUTH_CANCEL = 401
//        const val AUTH_FAILED = 402
//    }
//
//    private val mReceiver: BroadcastReceiver by lazy {
//        AuthBroadcastReceiver()
//    }
//
//    private var mAuthCallBack: AuthCallback? = null
//    fun setAuthCallback(callback: AuthCallback) {
//        this.mAuthCallBack = callback
//    }
//
//    /**
//     *赛科龙客户端是否安装
//     */
//    fun isInstalled(context: Context): Boolean {
//        return if (BuildConfig.FLAVOR_version.contains("product"))
//            isAppInstalled(context, "com.jczy.cyclone")
//        else
//            isAppInstalled(context, "com.jczy.cyclone.dev")
//    }
//
//    /**
//     *
//     * 调用赛科龙授权
//     */
//    fun auth(activity: Activity) {
//        //注册广播接受者,接收授权成功返回广播信
//        val intentFilter = IntentFilter()
//        // 自行定义action 即可,定义为被唤起的app包名
//        intentFilter.addAction(ACTION_AUTH)
//        activity.registerReceiver(mReceiver, intentFilter)
//        val result = runCatching {
//            val intent = Intent()
//            intent.setData(Uri.parse(AUTH_URL)) //参数拼接在URI后面 type=1是授权页面,user_package_name使用者包名,后续参数可自行添加
//            intent.setAction(Intent.ACTION_VIEW)
//            intent.addCategory(Intent.CATEGORY_DEFAULT)
//            activity.startActivity(intent)
//        }
//        if (result.isFailure) {
//            ToastUtils.showShort(appContext, "当前赛科龙版本不支持此功能")
//        }
//
//    }
//
//
//    /**
//     *
//     * AuthBroadcastReceiver 接收授权成功返回广播信息
//     */
//    inner class AuthBroadcastReceiver : BroadcastReceiver() {
//        override fun onReceive(context: Context?, intent: Intent) {
//            val code = intent.getIntExtra("code", -1)
//            val token = intent.getStringExtra("token")
//            val appPkg = intent.getStringExtra("app_pkg")
////            if (code == 0 && !token.isNullOrEmpty()) {
////                // 授权成功  返回token,app_pkg
////             //   Toast.makeText(appContext, "授权成功!", Toast.LENGTH_SHORT).show()
////                Log.d("xxx", "token=$token\napp_pkg=$appPkg")
////
////
////            } else if (code == 401) {
////                Toast.makeText(appContext, "取消授权!", Toast.LENGTH_SHORT).show()
////            } else {
////                // 授权成功  返回token,app_pkg
////                Toast.makeText(appContext, "授权失败!", Toast.LENGTH_SHORT).show()
////            }
//            mAuthCallBack?.onResult(code, token)
//            context?.unregisterReceiver(this)
//        }
//    }
//
//    interface AuthCallback {
//        fun onResult(code: Int, token: String?)
//    }
}